﻿using System;
using System.Windows;

namespace ZOIL.DataBackend.Server
{
    public partial class AddDatabaseDialog : Window
    {
        public AddDatabaseDialog()
        {
            InitializeComponent();
        }

        /// <summary>
        /// the database configuration that is created when the user clicks 'Add Database'
        /// </summary>
        public DatabaseConfiguration Database { get; private set; }

        /// <summary>
        /// Event handler for the 'Add Database' Button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddDb_Click(object sender, RoutedEventArgs e)
        {
            DatabaseConfiguration config = new DatabaseConfiguration();
            config.DatabaseFile = txtDbFileName.Text + ".yap";
            config.Description = txtDescription.Text;
            config.Name = txtDbName.Text;
            config.Port = Convert.ToInt32(txtPort.Text);
            Database = config;
            DialogResult = true;
        }

        /// <summary>
        /// Event Handler for the 'Cancel' Button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}
